package com.adaydayup.week_1017;

public class RemoveDup_1047 {
    public static String removeDuplicates(String s) {
        char[] a = s.toCharArray();
        int top = -1;
        for (int i = 0; i < a.length; i++) {
            if (top == -1 || a[top] != a[i]) {
                a[++top] = a[i];
            } else {
                top--;
            }
        }
        return String.valueOf(a, 0, top + 1);
    }

    public static void main(String[] args) {
        String s="abbaba";
        String s1 = removeDuplicates(s);
        System.out.println(s1);
    }
}
